from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-08 14:04:12.037479
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 08, Aug, 2022
Time: 14:04:18
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.0701
Nobs: 742.000 HQIC: -50.4137
Log likelihood: 9397.77 FPE: 1.02804e-22
AIC: -50.6292 Det(Omega_mle): 9.11346e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296679 0.055604 5.336 0.000
L1.Burgenland 0.107810 0.036850 2.926 0.003
L1.Kärnten -0.106839 0.019529 -5.471 0.000
L1.Niederösterreich 0.206841 0.076828 2.692 0.007
L1.Oberösterreich 0.109886 0.075023 1.465 0.143
L1.Salzburg 0.254101 0.039367 6.455 0.000
L1.Steiermark 0.041862 0.051380 0.815 0.415
L1.Tirol 0.108494 0.041682 2.603 0.009
L1.Vorarlberg -0.062170 0.035838 -1.735 0.083
L1.Wien 0.048309 0.066422 0.727 0.467
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058157 0.116202 0.500 0.617
L1.Burgenland -0.032060 0.077010 -0.416 0.677
L1.Kärnten 0.046989 0.040812 1.151 0.250
L1.Niederösterreich -0.175774 0.160555 -1.095 0.274
L1.Oberösterreich 0.407862 0.156784 2.601 0.009
L1.Salzburg 0.287794 0.082270 3.498 0.000
L1.Steiermark 0.107818 0.107375 1.004 0.315
L1.Tirol 0.311383 0.087106 3.575 0.000
L1.Vorarlberg 0.025199 0.074894 0.336 0.737
L1.Wien -0.029955 0.138810 -0.216 0.829
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189639 0.028547 6.643 0.000
L1.Burgenland 0.090201 0.018919 4.768 0.000
L1.Kärnten -0.008836 0.010026 -0.881 0.378
L1.Niederösterreich 0.261138 0.039443 6.621 0.000
L1.Oberösterreich 0.137514 0.038517 3.570 0.000
L1.Salzburg 0.045580 0.020211 2.255 0.024
L1.Steiermark 0.021136 0.026379 0.801 0.423
L1.Tirol 0.093312 0.021399 4.361 0.000
L1.Vorarlberg 0.055442 0.018399 3.013 0.003
L1.Wien 0.116086 0.034101 3.404 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107761 0.029007 3.715 0.000
L1.Burgenland 0.045868 0.019223 2.386 0.017
L1.Kärnten -0.013906 0.010188 -1.365 0.172
L1.Niederösterreich 0.189516 0.040078 4.729 0.000
L1.Oberösterreich 0.302147 0.039137 7.720 0.000
L1.Salzburg 0.109616 0.020536 5.338 0.000
L1.Steiermark 0.103951 0.026803 3.878 0.000
L1.Tirol 0.105738 0.021744 4.863 0.000
L1.Vorarlberg 0.068967 0.018695 3.689 0.000
L1.Wien -0.020467 0.034650 -0.591 0.555
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126330 0.052830 2.391 0.017
L1.Burgenland -0.050059 0.035012 -1.430 0.153
L1.Kärnten -0.040712 0.018555 -2.194 0.028
L1.Niederösterreich 0.170647 0.072994 2.338 0.019
L1.Oberösterreich 0.138692 0.071280 1.946 0.052
L1.Salzburg 0.288602 0.037403 7.716 0.000
L1.Steiermark 0.035729 0.048817 0.732 0.464
L1.Tirol 0.163314 0.039602 4.124 0.000
L1.Vorarlberg 0.100973 0.034050 2.965 0.003
L1.Wien 0.068553 0.063108 1.086 0.277
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056241 0.041994 1.339 0.180
L1.Burgenland 0.039493 0.027830 1.419 0.156
L1.Kärnten 0.051211 0.014749 3.472 0.001
L1.Niederösterreich 0.219231 0.058023 3.778 0.000
L1.Oberösterreich 0.294492 0.056660 5.198 0.000
L1.Salzburg 0.043766 0.029732 1.472 0.141
L1.Steiermark 0.000266 0.038804 0.007 0.995
L1.Tirol 0.143389 0.031479 4.555 0.000
L1.Vorarlberg 0.072287 0.027066 2.671 0.008
L1.Wien 0.080501 0.050164 1.605 0.109
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173966 0.050196 3.466 0.001
L1.Burgenland -0.002373 0.033266 -0.071 0.943
L1.Kärnten -0.062491 0.017630 -3.545 0.000
L1.Niederösterreich -0.076885 0.069355 -1.109 0.268
L1.Oberösterreich 0.188795 0.067726 2.788 0.005
L1.Salzburg 0.058041 0.035538 1.633 0.102
L1.Steiermark 0.234309 0.046383 5.052 0.000
L1.Tirol 0.498659 0.037627 13.253 0.000
L1.Vorarlberg 0.045225 0.032352 1.398 0.162
L1.Wien -0.054916 0.059962 -0.916 0.360
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160366 0.057873 2.771 0.006
L1.Burgenland -0.008058 0.038354 -0.210 0.834
L1.Kärnten 0.065793 0.020326 3.237 0.001
L1.Niederösterreich 0.205347 0.079963 2.568 0.010
L1.Oberösterreich -0.067065 0.078085 -0.859 0.390
L1.Salzburg 0.208824 0.040974 5.097 0.000
L1.Steiermark 0.121936 0.053477 2.280 0.023
L1.Tirol 0.073109 0.043383 1.685 0.092
L1.Vorarlberg 0.120452 0.037300 3.229 0.001
L1.Wien 0.120754 0.069133 1.747 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359241 0.033242 10.807 0.000
L1.Burgenland 0.007176 0.022030 0.326 0.745
L1.Kärnten -0.023728 0.011675 -2.032 0.042
L1.Niederösterreich 0.214551 0.045930 4.671 0.000
L1.Oberösterreich 0.200444 0.044851 4.469 0.000
L1.Salzburg 0.043546 0.023535 1.850 0.064
L1.Steiermark -0.013139 0.030716 -0.428 0.669
L1.Tirol 0.104727 0.024918 4.203 0.000
L1.Vorarlberg 0.070915 0.021425 3.310 0.001
L1.Wien 0.038234 0.039709 0.963 0.336
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039436 0.139048 0.191358 0.150948 0.117368 0.103002 0.063186 0.216501
Kärnten 0.039436 1.000000 -0.007480 0.132075 0.039321 0.094049 0.432886 -0.054010 0.097395
Niederösterreich 0.139048 -0.007480 1.000000 0.332965 0.141735 0.292879 0.096276 0.179456 0.312378
Oberösterreich 0.191358 0.132075 0.332965 1.000000 0.228172 0.325456 0.176128 0.165990 0.260247
Salzburg 0.150948 0.039321 0.141735 0.228172 1.000000 0.142388 0.112730 0.144926 0.123943
Steiermark 0.117368 0.094049 0.292879 0.325456 0.142388 1.000000 0.146507 0.137413 0.070648
Tirol 0.103002 0.432886 0.096276 0.176128 0.112730 0.146507 1.000000 0.112409 0.142471
Vorarlberg 0.063186 -0.054010 0.179456 0.165990 0.144926 0.137413 0.112409 1.000000 -0.000952
Wien 0.216501 0.097395 0.312378 0.260247 0.123943 0.070648 0.142471 -0.000952 1.000000